package itsm.isperp.module.controller.configuration;

import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.response.ResultMessage;
import itsm.isperp.module.entity.configuration.ConfCiRelationPlanProperty;
import itsm.isperp.module.entity.configuration.ConfCiRelationProperty;
import itsm.isperp.module.service.configuration.ConfCiRelationPlanPropertyService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 控制器
 * 
 * @author lizx
 * @date 2016-06-20 12:25
 */
@Controller
@RequestMapping("conf/ciRelationPlanProperty")
public class ConfCiRelationPlanPropertyController extends
		BaseController<ConfCiRelationPlanProperty> {

	@Autowired
	protected ConfCiRelationPlanPropertyService confCiRelationPlanPropertyService;

	@Override
	public ConfCiRelationPlanPropertyService getService() {
		return this.confCiRelationPlanPropertyService;
	}

	@Override
	public String getPageTitle() {
		return "配置关系属性";
	}

	@RequestMapping("saveProperties")
	@ResponseBody
	public ResultMessage saveProperties(String relationTypeId,
			String relationId, String[] relationTypePropertyName,
			String[] relationTypePropertyValue) {

		if (relationTypePropertyName == null
				|| relationTypePropertyName.length == 0) {
			return ResultMessage.failure();
		}
		for (int i = 0; i < relationTypePropertyName.length; i++) {
			ConfCiRelationPlanProperty p = new ConfCiRelationPlanProperty();
			p.setName(relationTypePropertyName[i]);
			p.setValue(relationTypePropertyValue[i]);
			p.setOrderNum(i);
			p.setRelationTypeId(relationTypeId);
			p.setRelationId(relationId);

			this.getService().saveOrUpdate(p);
		}

		return ResultMessage.success();
	}

}
